<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Card\Model;
use Think\Model;

/**
 * 用户模型
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */

class UserModel extends Model {

    public $sx_data = array();

    protected $_validate = array(
        //只在注册时验证
        array('name','','姓名不能为空',1,'notequal',1),//姓名不为空

        //编辑名片时验证
        array('name','','姓名不能为空',1,'notequal',4),
        array('moblie_phone','/^1[34578]\d{9}$/','请输入正确手机号',1,'regex',4),
        array('qq', '/[1-9][0-9]{4,14}/', 'qq号不正确', 2, 'regex', 4),
        array('homepage_url', 'url', '网址必须带http://或者https://', 2, 'regex', 4),
        array('weibo', 'url', '微博必须带http://', 2, 'regex', 4), 


    );

    /**
     * 查询单条用户信息
     */
    public function getMemberInfo($condition, $field = '*') {
        return $this->field($field)->where($condition)->find();
    }

    /**
     * 增加云名片
     */
    public function addCart(){
        if (!$this->create($this->sx_data,1)){
            $res['msg'] = $this->getError();
            $res['sta'] = -1;
            return $res;
        }else{
            $res = $this->add();
            return $res;
        }

    }

    /**
     * 编辑云名片
     */
    public function saveCart(){
        if (!$this->create($this->sx_data,4)){
            $res['msg'] = $this->getError();
            $res['sta'] = -1;
            return $res;
        }else{
            $res = $this->save();
            return $res;
        }

    }
    
    public function existBusinessCard($where)
    {
        return M('user')->where($where)->getField('id');
    }

}
